解决因为ssh无法连接的问题

问题:无法更新,出现报错

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s.
Please contact your system administrator.
Add correct host key in /Users/Yina/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/Yina/.ssh/known_hosts:1
Host key for github.com has changed and you have requested strict checking.
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html

问题关键词 密钥、known_hosts

许多 Git 服务器都使用 SSH 公钥进行认证。 为了向 Git 服务器提供 SSH 公钥,如果某系统用户尚未拥有密钥,必须事先为其生成一份。
known_hosts:记录远程主机的公钥的文件
报错原因:如果更新了系统,而保存的公钥还是未重装系统的系统公钥,在ssh链接的时候首先会验证公钥,如果公钥不对, 那么就会报错

推荐解决方案:使用shh-keygen -r 域名命令

进入SSH目录cd ~/.ssh 列出内容 ls

你需要确认自己是否已经拥有密钥。 默认情况下,用户的 SSH 密钥存储在其 ~/.ssh 目录下。 进入该目录并列出其中内容,你便可以快速确认自己是否已拥有密钥:

1
2
3
4
Yinas-Mac:~ Yina$ cd ~/.ssh
Yinas-Mac:.ssh Yina$ ls
config.yml github_rsa github_rsa.pub id_rsa id_rsa.pub known_hosts
Yinas-Mac:~ Yina$  ls -al ~/.ssh

如果发现有 id_rsa 和 id_rsa.pub ,则说明本地已存在SSH key了

id_rsa 本机生成的私钥文件
id_rsa.pub 本机生成的公钥文件

查看git服务器ip地址 ssh-keygen -l -f ~/.ssh/known_hosts

1
2
Yinas-Mac:~ Yina$ ssh-keygen -l -f ~/.ssh/known_hosts
2048 SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8 github.com,192.30.253.113 (RSA)

ssh-keygen -R 服务器端的ip地址

1
ssh-keygen -R 192.30.253.113

再次推送,成功。

参考资料

https://iwantjingjing.com/2018/05/11/WARNING-REMOTE-HOST-IDENTIFICATION-HAS-CHANGED/
https://blog.csdn.net/qq_36441027/article/details/81708726
https://www.jianshu.com/p/775af5f7a1d3

changelog

20230330 遇到问题,并解决